#include "loadingoverlay.h"
#include <QApplication>
#include <QFileDialog>
#include <QMessageBox>
#include <QStandardItemModel>
#include <QTableView>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLineEdit>
#include <QComboBox>
#include <QLabel>
#include <QDir>
#include <QFileInfo>
#include <QHeaderView>
#include <QDirIterator>
#include <QThread>
#include <QTimer>

class FileRenamer : public QWidget
{
    Q_OBJECT

public:
    FileRenamer(QWidget *parent = nullptr);
    ~FileRenamer();

private slots:
    void selectDirectory();
    void previewRename();
    void executeRename();
    void updateModelPreview();

signals:
    void sendLineEditText(QString);
    void sendComboboxText(QString);
    void sendReplacementText(QString);
    void sendFilePath(QString);
    void startPreviewThread();

private:
    void setupUI();
    void loadFileList();

    QDir currentDir;
    QStandardItemModel *model;
    QComboBox *operationCombo;
    QLineEdit *editText;
    QLineEdit *replacementText;
    bool buttonFlag{false};
    LoadingOverlay *load;
    QThread *m_thread;
};

class PreviewThread : public QObject
{
    Q_OBJECT

public:
    PreviewThread(QObject *parent = nullptr) : QObject(parent)
    {
    }

public slots:
    void getlineEditTextFromMainThread(QString text)
    {
        lineEditText = text;
    }
    void getComboBoxTextFromMainThread(QString text)
    {
        comboBoxText = text;
    }
    void getReplacementTextFromMainThread(QString text)
    {
        replacementText = text;
    }
    void getFilePathFromMainThread(QString path)
    {
        filePath = path;
    }
    void previewThreadRun();

signals:
    void sendNewName(QString);
    void finishLoop();

private:
    QString lineEditText;
    QString comboBoxText;
    QString replacementText;
    QString filePath;
};
